#ifndef _AS_COMMON_H_
#define _AS_COMMON_H_


#define AS_IN_COCOS
#ifdef AS_IN_COCOS
#include "cocos2d.h"
#else

#endif

#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include "utils.h"
#include "geometry.h"
#include "Transformations.h"
#include "Vector2D.h"
#include "C2DMatrix.h"
#include "sigslot.h"


#define ASDEBUG
#ifdef ASDEBUG
	#ifdef AS_IN_COCOS
#define ASLog(format,...)	CCLOG(format,##__VA_ARGS__)
		#define ASAssert(cond,msg)	CCAssert(cond,msg)
	#else
		#define ASLog(format,...)	do{printf(format,##__VA_ARGS__);}while(0)
		#define ASAssert(cond,msg)	do {if (!(cond)) {\
										if (strlen(msg))\
										  ASLog("Assert failed: %s", msg);\
										assert(cond);\
									  } } while (0)
	#endif
#else
	#define ASLog		do {} while(0)
	#define ASAssert	do {} while(0) 
#endif
#define NS_AS_BEGIN		namespace AS {
#define NS_AS_END		}
#define USING_NS_AS		using namespace AS


#define AS_PROPERTY_READONLY(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void);

#define AS_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\
protected: varType varName;\
public: virtual const varType& get##funName(void);

#define AS_PROPERTY(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void);\
public: virtual void set##funName(varType var);

#define AS_PROPERTY_PASS_BY_REF(varType, varName, funName)\
protected: varType varName;\
public: virtual const varType& get##funName(void);\
public: virtual void set##funName(const varType& var);

#define AS_SYNTHESIZE_READONLY(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void) const { return varName; }

#define AS_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\
protected: varType varName;\
public: virtual const varType& get##funName(void) const { return varName; }

#define AS_SYNTHESIZE(varType, varName, funName)\
protected: varType varName;\
public: virtual varType get##funName(void) const { return varName; }\
public: virtual void set##funName(varType var){ varName = var; }

#define AS_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\
protected: varType varName;\
public: virtual const varType& get##funName(void) const { return varName; }\
public: virtual void set##funName(const varType& var){ varName = var; }


#define AS_SAFE_DELETE(p)           do { delete (p); (p) = nullptr; } while(0)
#define AS_SAFE_DELETE_ARRAY(p)     do { if(p) { delete[] (p); (p) = nullptr; } } while(0)
#define AS_SAFE_FREE(p)             do { if(p) { free(p); (p) = nullptr; } } while(0)
#ifdef ASOBJ_REFCOUNT
#define AS_SAFE_RELEASE(p)          do { if(p) { (p)->release(); } } while(0)
#define AS_SAFE_RELEASE_NULL(p)     do { if(p) { (p)->release(); (p) = nullptr; } } while(0)
#define AS_SAFE_RETAIN(p)           do { if(p) { (p)->retain(); } } while(0)
#endif

#define AS_VECTOR_ACCURACY 1000//0.001
#define AS_VECTOR_MIN 0.01

#endif